/**
 * 
 */
package com.cip.master.dao.impl;
import java.util.List;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.cip.admin.dao.impl.CipHibernateDAOSupport;
import com.cip.master.dao.HomeWorkDAO;
import com.cip.master.model.HomeWork;
import com.cip.master.model.Result;

/**
 * @author simbu
 *
 */
public class HomeWorkDAOImpl extends CipHibernateDAOSupport implements HomeWorkDAO {
	
	public HomeWork getHomeWorkById(int id) throws Exception{
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();	
		return hibernateTemplate.get(HomeWork.class,id);
	}
	
	public HomeWork saveOrUpdateHomeWork(HomeWork homeWork) throws Exception{
		
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();	
		hibernateTemplate.saveOrUpdate(homeWork);
		return homeWork;
	}
	
	public HomeWork editHomeWork(HomeWork homeWork) throws Exception{
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();	
		hibernateTemplate.saveOrUpdate(homeWork);
		return homeWork;
		
	}

	public List<HomeWork> getAllHomeWorkList() throws Exception {
		HibernateTemplate hibernateTemplate = getCipHibernateTemplate();	
		return hibernateTemplate.loadAll(HomeWork.class);
	}
	public List<HomeWork> getAllHomeWorkListByClass(int section, int classYear)throws Exception{
		String query="select homework from  HomeWork as homework where homework.status='Active' and homework.section='"+section+"' and homework.classYear='"+classYear+"'"  ;
		List<HomeWork> results = getCipHibernateTemplate().find(query);
		return results;

	}


}
